package com.crm.dao.repositories;

import com.crm.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author misterWei
 * @create 2018年11月15号:10点09分
 * @mailbox mynameisweiyan@gmail.com
 */
public interface CustomerRepositorie extends JpaRepository<Customer,Integer>,JpaSpecificationExecutor<Customer> {
       //查询客户还没有与定区绑定的数据
       @Query(" from Customer where fixedAreaId is Null")
       public List<Customer> findIsNullFixedArea();

       //查询客户与该地区绑定的数据  //命名规则查询
       public List<Customer> findByFixedAreaId(String fixedAreaId);

       //修改客户与定区的绑定数据
    @Query("update Customer set fixedAreaId = ?2 where id = ?1")
    @Modifying
    public void customerToFixedArea(Integer id,String fixedAreaId);
     //自定义 如果不给customer参数,默认设置为 null
    @Query("update  Customer  set fixedAreaId = null  where fixedAreaId=?1")
    @Modifying
    void customerIdAsNull(String fixedAreaId);

    Customer findByTelephone(String telephone);

      @Query("update Customer set type = 1 where telephone = ?1")
      @Modifying
    void updateEmailStatus(String telephone);


    Customer findByTelephoneAndPassword(String telephone, String password);
     @Query("select fixedAreaId from Customer where address=?1")
    String findFixedAreaByAddress(String address);
}
